package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsOrderMapper;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsOrderService;
import com.qf.vo.DayStatis;
import com.qf.vo.OrderAmtsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author lixu
 */
@Service
public class DtsOrderServiceImpl implements DtsOrderService {
    @Autowired
    private DtsOrderMapper dtsOrderMapper;
    /**
     * 日期和对应的订单总额, 订单笔数  select count(1),sum(actual_price)
     * @return
     * @param statisDaysRang
     */
    @Override
    public List<DayStatis> findOrderAmtsVo(int statisDaysRang) {

        //一个日期对应一个订单笔数  及订单金额
        return dtsOrderMapper.findOrderAmtsVo(statisDaysRang);

    }

    /**
     * 查询分页
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    @Override
    public IPage<DtsOrder> findPage(Integer page, Integer limit, String sort, String order) {
        return dtsOrderMapper.selectPage(new Page<DtsOrder>(page,limit),new QueryWrapper<DtsOrder>()
                .orderBy(StringUtils.isEmpty(sort)?false:true,
                        "asc".equalsIgnoreCase(order)?true:false,sort));
    }
}
